import { message } from 'antd';

import api from '../../api';

export default {
  namespace: 'stressTestReportSettingsM',
  state: {
    SCENARIO_CATEGORY_columns: [
      {
        title: '情景假设类别',
        key: 'name',
        dataIndex: 'name',
        width: '28%',
      },
      {
        title: '轻度假设',
        key: 'low',
        dataIndex: 'low',
        width: '24%',
        align: 'right',
      },
      {
        title: '中度假设',
        key: 'medium',
        dataIndex: 'medium',
        width: '24%',
        align: 'right',
      },
      {
        title: '重度假设',
        key: 'high',
        dataIndex: 'high',
        width: '24%',
      },
    ],
    CREDIT_DEFAULT_RATE_columns: [
      {
        title: '信用债违约率',
        key: 'name',
        dataIndex: 'name',
        width: '28%',
      },
      {
        title: '轻度假设',
        key: 'low',
        dataIndex: 'low',
        width: '24%',
        align: 'right',
      },
      {
        title: '中度假设',
        key: 'medium',
        dataIndex: 'medium',
        width: '24%',
        align: 'right',
      },
      {
        title: '重度假设',
        key: 'high',
        dataIndex: 'high',
        width: '24%',
      },
    ],
    BOND_YIELD_CURVE_UPSIDE_CREDIT_BOND_colunms: [
      { title: '债券收益率曲线上移幅度（信用债）', key: 'name', dataIndex: 'name' },
      {
        title: '轻度假设',
        key: 'low',
        dataIndex: 'low',
        width: '24%',
        align: 'right',
      },
      {
        title: '中度假设',
        key: 'medium',
        dataIndex: 'medium',
        width: '24%',
        align: 'right',
      },
      {
        title: '重度假设',
        key: 'high',
        dataIndex: 'high',
        width: '24%',
      },
    ],
    BOND_YIELD_CURVE_UPSIDE_INTEREST_RATE_BOND_colunms: [
      {
        title: '债券收益率曲线上移幅度（利率债）',
        key: 'name',
        dataIndex: 'name',
        width: '28%',
      },
      {
        title: '轻度假设',
        key: 'low',
        dataIndex: 'low',
        width: '24%',
        align: 'right',
      },
      {
        title: '中度假设',
        key: 'medium',
        dataIndex: 'medium',
        width: '24%',
        align: 'right',
      },
      {
        title: '重度假设',
        key: 'high',
        dataIndex: 'high',
        width: '24%',
      },
    ],
    OTHER_PARAMETER_SETTINGS_colunms: [
      {
        title: '其它参数设置',
        key: 'name',
        dataIndex: 'name',
        width: '28%',
      },
      {
        title: '轻度假设',
        key: 'low',
        dataIndex: 'low',
        width: '24%',
        align: 'right',
      },
      {
        title: '中度假设',
        key: 'medium',
        dataIndex: 'medium',
        width: '24%',
        align: 'right',
      },
      {
        title: '重度假设',
        key: 'high',
        dataIndex: 'high',
        width: '24%',
      },
    ],
    BOND_YIELD_CURVE_UP_BP_colunms: [
      {
        title: '债券收益率曲线上移幅度',
        key: 'name',
        dataIndex: 'name',
        width: '28%',
      },
      {
        title: '轻度假设',
        key: 'low',
        dataIndex: 'low',
        width: '24%',
        align: 'right',
      },
      {
        title: '中度假设',
        key: 'medium',
        dataIndex: 'medium',
        width: '24%',
        align: 'right',
      },
      {
        title: '重度假设',
        key: 'high',
        dataIndex: 'high',
        width: '24%',
      },
    ],
    NON_STANDARD_BUSINESS_SCENARIO_colunms: [
      {
        title: '非标业务情景',
        key: 'name',
        dataIndex: 'name',
        width: '28%',
      },
      {
        title: '轻度假设',
        key: 'low',
        dataIndex: 'low',
        width: '24%',
        align: 'right',
      },
      {
        title: '中度假设',
        key: 'medium',
        dataIndex: 'medium',
        width: '24%',
        align: 'right',
      },
      {
        title: '重度假设',
        key: 'high',
        dataIndex: 'high',
        width: '24%',
      },
    ],
    OTHER_PARAM_CONFIG_colunms: [
      {
        title: '配置项',
        key: 'name',
        dataIndex: 'name',
        width: '28%',
      },
      {
        title: '轻度假设',
        key: 'low',
        dataIndex: 'low',
        width: '24%',
        align: 'right',
      },
      {
        title: '中度假设',
        key: 'medium',
        dataIndex: 'medium',
        width: '24%',
        align: 'right',
      },
      {
        title: '重度假设',
        key: 'high',
        dataIndex: 'high',
        width: '24%',
      },
    ],
  },
  effects: {
    // 获取情景下拉列表
    *getScenes({ payload, callback }, { call }) {
      const res = yield call(api.sceneSettings.getScenes, payload);
      if (res?.code === 0) {
        callback(res.data);
      }
    },
    *stressTestConfig({ payload, callback }, { call }) {
      const res = yield call(api.sceneSettings.stressTestConfig, payload);
      if (res?.code == 0) {
        callback(res.data);
      }
    },
    *stressTestConfigSave({ payload, callback }, { call }) {
      const res = yield call(api.sceneSettings.stressTestConfigSave, payload);
      if (res?.code == 0) {
        callback(true);
        message.success('保存成功！');
      } else {
        message.error(res?.msg || '保存失败');
      }
    },
    // 校验情景名称
    *checkSceneName({ payload, callback }, { call }) {
      const res = yield call(api.sceneSettings.checkSceneName, payload);
      if (res?.code == 0) {
        callback(true);
      } else {
        message.error((res && res.msg) || '校验失败');
      }
    },
    // 新增情景
    *sceneSettingsSave({ payload, callback }, { call }) {
      const res = yield call(api.sceneSettings.sceneSettingsSave, payload);
      if (res?.code == 0) {
        callback(res);
      } else {
        message.error(res && res.msg);
      }
    },
    // 编辑情景名称
    *sceneSettingsEditSceneName({ payload, callback }, { call }) {
      const res = yield call(api.sceneSettings.sceneSettingsEditSceneName, payload);
      if (res?.code == 0) {
        callback(res);
      } else {
        message.error(res && res.msg);
      }
    },
    // 删除情景
    *sceneSettingsDelete({ payload, callback }, { call }) {
      const res = yield call(api.sceneSettings.sceneSettingsDelete, payload);
      if (res?.code == 0) {
        callback(res);
      } else {
        message.error(res && res.msg);
      }
    },
    // 获取模板下拉列表
    *getModels({ payload, callback }, { call }) {
      const res = yield call(api.sceneSettings.getModels, payload);
      if (res?.code === 0) {
        callback(res.data);
      }
    },
    // 获取模板详情
    *getModelInfo({ payload, callback }, { call }) {
      const res = yield call(api.sceneSettings.getModelInfo, payload);
      if (res?.code === 0) {
        callback(res.data);
      }
    },
    // 校验模板名称
    *checkModelName({ payload, callback }, { call }) {
      const res = yield call(api.sceneSettings.checkModelName, payload);
      if (res?.code == 0) {
        callback(true);
      } else {
        message.error((res && res.msg) || '校验失败');
      }
    },
    // 新增模板
    *modelSettingsSave({ payload, callback }, { call }) {
      const res = yield call(api.sceneSettings.modelSettingsSave, payload);
      if (res?.code == 0) {
        callback(res);
      } else {
        message.error(res && res.msg);
      }
    },
    // 编辑模板名称
    *modelSettingsEditModelName({ payload, callback }, { call }) {
      const res = yield call(api.sceneSettings.modelSettingsEditSceneName, payload);
      if (res?.code == 0) {
        callback(res);
      } else {
        message.error(res && res.msg);
      }
    },
    // 删除模板
    *modelSettingsDelete({ payload, callback }, { call }) {
      const res = yield call(api.sceneSettings.modelSettingsDelete, payload);
      if (res?.code == 0) {
        callback(res);
      } else {
        message.error(res && res.msg);
      }
    },

    // 编辑模板内容修改
    *modifyTemplateModule({ payload, callback }, { call }) {
      const res = yield call(api.sceneSettings.modifyTemplateModule, payload);
      if (res?.code == 0) {
        callback(true);
      } else {
        message.error(res && res.msg);
      }
    },

    // 情景模板删除判断
    *judgeUsageStatus({ payload, callback }, { call }) {
      const res = yield call(api.sceneSettings.judgeUsageStatus, payload);
      if (res?.code == 0) {
        callback(res.data);
      } else {
        message.error(res && res.msg);
      }
    },
  },
  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
